#ifndef __ONEWIRE_H__
#define __ONEWIRE_H__
#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
#include "tim.h"
#include "configureation.h"
#include "Common_Debug.h"

#define  DEM_CR      *(volatile uint32_t *)0xE000EDFC
#define  DWT_CR      *(volatile uint32_t *)0xE0001000
#define  DWT_CYCCNT  *(volatile uint32_t *)0xE0001004
#define  DEM_CR_TRCENA                   (1 << 24)
#define  DWT_CR_CYCCNTENA                (1 <<  0)

// #define DQ_GPIO_Port GPIOB
// #define DQ_Pin GPIO_PIN_5
#define DQ_IN HAL_GPIO_ReadPin(DS18B20_DATA_GPIO_Port, DS18B20_DATA_Pin)

void DWT_Init(void);
void DWT_DelayUS(uint32_t _ulDelayTime);
void DWT_DelayMS(uint32_t _ulDelayTime);

// /* Pin settings */
void ONEWIRE_LOW(void);			
void ONEWIRE_HIGH(void);		
// void ONEWIRE_INPUT(OneWire_t *gp);		
// void ONEWIRE_OUTPUT(OneWire_t *gp);		

/* OneWire commands */
#define ONEWIRE_CMD_RSCRATCHPAD			0xBE
#define ONEWIRE_CMD_WSCRATCHPAD			0x4E
#define ONEWIRE_CMD_CPYSCRATCHPAD		0x48
#define ONEWIRE_CMD_RECEEPROM			0xB8
#define ONEWIRE_CMD_RPWRSUPPLY			0xB4
#define ONEWIRE_CMD_SEARCHROM			0xF0
#define ONEWIRE_CMD_READROM				0x33
#define ONEWIRE_CMD_MATCHROM			0x55
#define ONEWIRE_CMD_SKIPROM				0xCC
#define ONEWIRE_CMD_TEMP				0x44

//#######################################################################################################


Status OneWire_Init(void);
void OneWire_WriteByte(uint8_t byte);
uint8_t OneWire_ReadByte(void);

#endif

